package com.ldh.springfox_swagger.controller;

import com.ldh.springfox_swagger.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LiuDehuai
 * @fileName:HelloController
 * @Date:2020/10/15 13:36
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/users")
public class HelloController {
    final static List<User> result = new ArrayList<>();

    static{
        result.add(new User("aa", 11, "上海", "a@c.com"));
        result.add(new User("bb", 12, "重庆", "b@c.com"));
        result.add(new User("ldh", 26, "杭州", "liudh_work@163.com"));
    }

    @ApiOperation("创建用户")
    @PostMapping
    public User create(@RequestBody @Valid User user) {
        return user;
    }

    @ApiOperation("用户详情")
    @GetMapping("/{id}")
    public User findById(@PathVariable Long id) {
        return result.get(2);
    }

    @ApiOperation("用户列表")
    @GetMapping
    public List<User> list(@ApiParam("页码") @RequestParam int pageIndex, @ApiParam("每页条数") @RequestParam int pageSize) {
        return result;
    }

    @ApiIgnore
    @DeleteMapping("/{id}")
    public String deleteById(@PathVariable Long id) {
        return "delete user:" + id;
    }
}
